import 'package:efood_multivendor/controller/localization_controller.dart';
import 'package:efood_multivendor/controller/order_controller.dart';
import 'package:efood_multivendor/helper/size_config.dart';
import 'package:efood_multivendor/util/dimensions.dart';
import 'package:efood_multivendor/util/styles.dart';
import 'package:efood_multivendor/view/base/custom_button.dart';
import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
import 'package:get/get.dart';

import '../../../../controller/splash_controller.dart';
import '../../../../data/model/response/config_model.dart';
import '../../../../helper/responsive_helper.dart';
import '../../../base/cancellation_reason_btn.dart';

class CancellationDialog extends StatelessWidget {
  final int? orderId;
  final int? orderIndex;
  final bool? fromOrderList;
  final OrderController? orderController;
  UserCancellationModel? userCancellation =
      Get.find<SplashController>().configModel?.userCancellationReason;
  UserCancellationAmharicModel? userCancellationAmharicModel =
      Get.find<SplashController>()
          .configModel
          ?.userCancellationReason
          ?.userCancellationAmharic;
  UserCancellationEnglishModel? userCancellationEnglishModel =
      Get.find<SplashController>()
          .configModel
          ?.userCancellationReason
          ?.userCancellationEnglishModel;
  UserCancellationChineseModel? userCancellationChineseModel =
      Get.find<SplashController>()
          .configModel
          ?.userCancellationReason
          ?.userCancellationChineseModel;

  CancellationDialog({
    this.orderId,
    this.orderController,
    this.orderIndex,
    this.fromOrderList = false,
  });

  @override
  Widget build(BuildContext context) {
    List<dynamic> ids = [];
    List<dynamic> bodys = [];
    if (Get.find<LocalizationController>().selectedIndex == 0) {
      ids = userCancellationEnglishModel?.englishIds ?? [];
      bodys = userCancellationEnglishModel?.englishBody ?? [];
    } else if (Get.find<LocalizationController>().selectedIndex == 1) {
      ids = userCancellationAmharicModel?.amharicIds ?? [];
      bodys = userCancellationAmharicModel?.amharicBody ?? [];
    } else if (Get.find<LocalizationController>().selectedIndex == 2) {
      ids = userCancellationChineseModel?.chineseIds ?? [];
      bodys = userCancellationChineseModel?.chineseBody ?? [];
    }

    return Container(
      width: 650.w,
      height: 45.h,
      padding: EdgeInsets.only(
        left: Dimensions.PADDING_SIZE_DEFAULT,
        bottom: Dimensions.PADDING_SIZE_SMALL,
        right: Dimensions.PADDING_SIZE_DEFAULT,
      ),
      decoration: BoxDecoration(
        color: Theme.of(context).cardColor,
        borderRadius: ResponsiveHelper.isMobile(context)
            ? BorderRadius.vertical(
                top: Radius.circular(Dimensions.RADIUS_EXTRA_LARGE))
            : BorderRadius.all(Radius.circular(Dimensions.RADIUS_EXTRA_LARGE)),
      ),
      child: GetBuilder<OrderController>(builder: (orderController) {
        return !orderController.isLoading
            ? Column(
                children: [
                  SizedBox(
                    height: 18,
                  ),
                  Text("Why_are_you_cancelling".tr,
                      style: sfRegular.copyWith(
                          fontSize: Dimensions.fontSizeDefault * 1.3,
                          fontWeight: FontWeight.w700,
                          color: Colors.black)),
                  SizedBox(
                    height: 12,
                  ),
                  ListView.builder(
                      shrinkWrap: true,
                      physics: NeverScrollableScrollPhysics(),
                      itemCount: ids.length + 1,
                      itemBuilder: (context, index) {
                        return Column(children: [
                          SizedBox(),
                          index != ids.length
                              ? CancellationButton(
                                  onPressed: () {
                                    orderController.cancelOrder(
                                      orderId!,
                                      ids[index],
                                    );
                                    if (fromOrderList == true) {
                                      orderController.cancelTimer(orderIndex!);
                                    }
                                  },
                                  margin: EdgeInsets.only(
                                      top: 5, left: 5, right: 5, bottom: 5),
                                  buttonText: bodys[index].toString(),
                                  width: 87.w,
                                )
                              : SizedBox(
                                  child: CustomButton(
                                    onPressed: () {
                                      Get.back();
                                    },
                                    margin: EdgeInsets.only(
                                        top: 5, left: 5, right: 5, bottom: 10),
                                    buttonText: 'Dont_Cancel'.tr,
                                    width: 87.w,
                                  ),
                                )
                        ]);
                      }),
                ],
              )
            : Center(
                child: CircularProgressIndicator.adaptive(
                  backgroundColor: Theme.of(context).colorScheme.secondary,
                ),
              );
      }),
    );
  }
}
